package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.service.AlertRuleService;
import com.zzyl.vo.AlertRuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/alert-rule")
@Api(tags = "报警规则接口")
public class AlertRuleController extends BaseController {

    @Autowired
    private AlertRuleService alertRuleService;

    @PostMapping("/create")
    @ApiOperation("新增规则")
    public ResponseResult alertRuleCreate(@RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.alertRuleCreate(alertRuleDto);
        return success();
    }

    @GetMapping("/get-page")
    @ApiOperation("分页查询规则")
    public ResponseResult<PageResponse<AlertRuleVo>> getPageAlertRule(Integer pageNum, Integer pageSize, String alertRuleName, String functionName, String productKey) {
        PageResponse<AlertRuleVo> alertRuleVoPageResponse = alertRuleService.getPageAlertRule(pageNum, pageSize, alertRuleName, functionName, productKey);
        return success(alertRuleVoPageResponse);
    }

    @GetMapping("/read/{id}")
    @ApiOperation("获取单个告警规则")
    public ResponseResult<AlertRuleVo> showAlertRuleById(@PathVariable Integer id) {
        AlertRuleVo alertRuleVo = alertRuleService.showAlertRuleById(id);
        return success(alertRuleVo);
    }

    @PutMapping("/update/{id}")
    @ApiOperation("更新告警规则")
    public ResponseResult updateAlertRuleById(@PathVariable Long id, @RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.updateAlertRuleById(alertRuleDto);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用-禁用")
    public ResponseResult updateAlertRuleStatusById(@PathVariable Long id, @PathVariable Integer status) {
        alertRuleService.updateAlertRuleStatusById(id, status);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除告警规则")
    public ResponseResult deleteAlertRuleById(@PathVariable Long id) {
        alertRuleService.deleteAlertRuleById(id);
        return success();
    }
}
